import requests
 
# 配置你的Gitee个人访问令牌
gitee_access_token = '99270206af0c655b6be8606001584c4f'
 
# 读取包含仓库地址的文件
with open('repositories.txt', 'r') as f:
    repositories = f.readlines()
 
# 定义批量导入的API
gitee_import_url = 'https://gitee.com/api/v5/SpikeXue_Admin/repos/migrate'
 
# 批量导入仓库
for repo in repositories:
    repo_url = repo.strip()  # 去除空白字符和换行符
    data = {
        'clone_addr': repo_url  # 仓库地址
    }
    headers = {
        'Authorization': 'token ' + gitee_access_token  # 设置认证头部
    }
    response = requests.post(gitee_import_url, json=data, headers=headers)
    if response.status_code == 201:
        print(f'{repo_url} 已成功导入。')
    else:
        print(f'{repo_url} 导入失败: {response}')
